package com.object.configuration.rabbitmq;


import com.common.rabitmq.RabbitmqName;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 发布订阅模式 配置
 */


@Configuration
public class TopicConfigtion {
    // 发布订阅模式
// 声明两个队列
    //消费者的队列
    @Bean
    public Queue queue_consumer() {
        return new Queue(RabbitmqName.rapid_consumer);
    }

    //网关队列
    @Bean
    public Queue queue_gateway() {
        return new Queue(RabbitmqName.rapid_gateway);
    }

    //支付队列
    @Bean
    public Queue queue_pay() {
        return new Queue(RabbitmqName.rapid_pay);
    }


    // 准备一个交换机
    @Bean
    public TopicExchange exchangeTopic() {
        return new TopicExchange("exchange_topic");
    }

    // 将交换机和队列进行绑定    绑定我们 写好的枚举路由 也是 我们的消费者和 网关
    @Bean
    public Binding bindingExchange1() {
        return BindingBuilder.bind(queue_consumer()).to(exchangeTopic()).with(RabbitmqName.rapid_consumer_routing_key);
    }

    //网关
    @Bean
    public Binding bindingExchange2() {
        return BindingBuilder.bind(queue_gateway()).to(exchangeTopic()).with(RabbitmqName.rapid_gateway_routing_key);
    }

    //支付
    @Bean
    public Binding bindingExchangPay() {
        return BindingBuilder.bind(queue_pay()).to(exchangeTopic()).with(RabbitmqName.rapid_pay_routing_key);
    }


}
